package com.lj.back.manage.scaffold.module.sys.dao;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.lj.back.manage.scaffold.module.sys.DO.SysUserRoleDO;
import org.apache.ibatis.annotations.Mapper;
import org.springframework.stereotype.Repository;

import javax.validation.constraints.NotNull;

/**
 * 后台管理---用户角色dao
 * @author lv
 * @version 1.0.0
 */
@Mapper
@Repository
public interface SysUserRoleDao extends BaseMapper<SysUserRoleDO> {

    /**
     * 根据用户ID删除用户角色关联关系
     * @param userId 用户ID
     * @return
     */
    default int deleteUserRoleByUserId(@NotNull(message = "{user.id.notnull}") Long userId){
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq("user_id",userId);
        return delete(queryWrapper);
    }

    /**
     * 根据角色ID删除用户角色关联关系
     * @param roleId 角色ID
     * @return
     */
    default int deleteUserRoleByRoleId(@NotNull(message = "{role.id.notnull}") Long roleId){
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq("role_id",roleId);
        return delete(queryWrapper);
    }
}
